package cn.com.bob.library.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.com.bob.library.entity.BookType;
import cn.com.bob.library.service.BookTypeService;
import cn.com.bob.library.mapper.BookTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 12948
* @description 针对表【book_type】的数据库操作Service实现
* @createDate 2023-06-30 08:27:12
*/
@Service
public class BookTypeServiceImpl extends ServiceImpl<BookTypeMapper, BookType>
    implements BookTypeService{

    @Autowired
    private BookTypeMapper bookTypeMapper;

    /**
     * 增加某类图书的数量
     * @param typeId:
     * @return void
     */
    @Override
    public void addBookSum(Integer typeId) {
        BookType type = bookTypeMapper.selectOne(new QueryWrapper<BookType>().eq("category_id", typeId));
        type.setQuantity(type.getQuantity() + 1);
        bookTypeMapper.update(type,new QueryWrapper<BookType>().eq("category_id",typeId));
    }

    @Override
    public void subBookSum(Integer typeId) {
        BookType type = bookTypeMapper.selectOne(new QueryWrapper<BookType>().eq("category_id", typeId));
        type.setQuantity(type.getQuantity() - 1);
        bookTypeMapper.update(type,new QueryWrapper<BookType>().eq("category_id",typeId));
    }
}




